package com.lz.football.module.ladderMatch.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.club.vo.TeamIconVo;
	import com.liangzhong.model.friend.vo.FriendInfoVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 *天梯排名  
	 * @author Administrator
	 * 
	 */	
	public class LadderRankItem extends Sprite implements IBaseItem, IComponent
	{
		private  var _skin:MovieClip;
		
		
		//		/**
		//		 *名次 
		//		 */
		//		private var ranking:TextField;
		/**
		 *名称  
		 */
		private var playerName:TextField;
		/**
		 *积分 
		 */
		private var integral:TextField;
		
		/**
		 *队徽图标  
		 */
		private var icon:MovieClip;
		/**
		 *排名 
		 */
		private var rank:MovieClip;
		private var _data:*;
		public function LadderRankItem()
		{
			super();
		}
		
		public function set data(value:*):void
		{
			_data = value;
			//			ranking.text = _data.sort + "";
			playerName.text = _data.name + "";
			integral.text = _data.ladderintegral +"";
			
			DisplayObjectUtil.removeAllChildren(icon);
			
			
			
			
			
			addEvtListener();
//			var vo:TeamIconVo = AppData.getInstance().clubDatamanager.getTeamIconVo(_data.logo);
			if(AppData.getInstance().clubDatamanager.getTeamIconVo(_data.logo) == null)return;
			var lo:MovieClip = Reflection.createInstance(AppData.getInstance().clubDatamanager.getTeamIconVo(_data.logo).iconurl);
			lo.scaleX = lo.scaleY = 0.25;
			lo.x = -lo.width >> 1;
			lo.y = -lo.height >> 1;
			icon.addChild(lo);
			
			
		}
		
		public function get data():*
		{
			
			return _data;
		}
		
		public function initUI(view:Object=null):void
		{
			_skin = Reflection.createInstance("com.lz.modul.ladderMatch.initranking");
			if(_skin == null)return;
			this.addChild(_skin);
			this.buttonMode = true;
			//			ranking = _skin.ranking;
			playerName = _skin.playerName;
			integral = _skin.integral;
			rank = _skin.rank;
			//			ranking.mouseEnabled = false;
			icon = _skin.icon;
			icon.mouseChildren = false;
			icon.mouseEnabled = false;
			playerName.mouseEnabled = false;
			integral.mouseEnabled = false;
		}
		/**
		 * 0xFFFFFF 
		 * @param value
		 * 
		 */		
		public function set textColor(value:uint):void
		{
			//			ranking.textColor = value;
//			playerName.textColor = value;
//			integral.textColor = value;
			rank.gotoAndStop(value);
		}
		/**
		 *重置 
		 * 
		 */
		private function reset():void
		{
			DisplayObjectUtil.removeAllChildren(icon);
			
		}
		/**
		 * 设置自己的信息 
		 * 
		 */
		public function setSelf():void
		{
			_data = AppData.getInstance().ladderDataManger.ladderInfovo;
			//			ranking.text =AppData.getInstance().ladderDataManger.ladderInfovo.ladderrank + "";
			playerName.text = AppData.getInstance().clubDatamanager.clubInfo.uname + "";
			integral.text = AppData.getInstance().ladderDataManger.ladderInfovo.ladderintegral + "";
			addEvtListener();
		}
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.CLICK,onclickHandler);
		}
		
		/**
		 *查看信息 
		 * @param event
		 * 
		 */
		protected function onclickHandler(event:MouseEvent):void
		{
			if(data == null || data.clubid <=0)return;
			var f:FriendInfoVo = new FriendInfoVo();
			f.friendid = data.clubid;
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.LOOK_UP_FRIEND,{vo:f}));
		}
		
		public function removeEvtListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,onclickHandler);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			if(this.parent)
				this.parent.removeChild(this);
			_skin = null;
		}
	}
}